﻿using Microsoft.Xna.Framework;

namespace Engine.Oct
{
    public class OctTree
    {
        public void Build(IOctObject[] objects)
        {
            float min = float.MaxValue;
            float max = float.MinValue;

            foreach (IOctObject octObject in objects)
            {                
                BoundingBox box = octObject.BoundingBox;
                min = MathHelper.Min(min, box.Min.X);
                min = MathHelper.Min(min, box.Min.Y);
                min = MathHelper.Min(min, box.Min.Z);

                max = MathHelper.Max(max, box.Max.X);
                max = MathHelper.Max(max, box.Max.Y);
                max = MathHelper.Max(max, box.Max.Z);

            }
            OctNode root = new OctNode(null,new BoundingBox(new Vector3(min), new Vector3(max)));            

            Root = root;
            Root.BuildNode(objects);
        }
        public OctNode Root { get;private set; }
    }
}
